<template>
  <div class="page">
    <NavBar/>
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
    <Footer/>
    <Loading v-show="isloading"/>
  </div>
</template>

<script type="text/ecmascript-6">
import NavBar from "./components/NavBar";
import Landing from "./components/Landing";
import Footer from "./components/Footer";
import jwt_decode from "jwt-decode";
import Loading from "./components/common/loading";

export default {
  data() {
    return {};
  },
  components: {
    NavBar,
    Landing,
    Footer,
    Loading
  },
  computed: {
    isloading() {
      return this.$store.getters.loading;
    }
  },
  created() {
    if (localStorage.jwt) {
      const decode = jwt_decode(localStorage.jwt);
      // console.log(decode);
      //获取现在的事件n
      const currentTime = Date.now() / 1000;

      //判断token是否过期
      if (currentTime > decode.exp) {
        this.$store.dispatch("setIsAuthenticated", false);
        this.$store.dispatch("setUser", {});
        this.$router.push("/login");
      } else {
        this.$store.dispatch("setIsAuthenticated", true);
        this.$store.dispatch("setUser", decode);
      }
    }
  }
};
</script>

<style scoped lang="stylus">
</style>
